package com.general.framework.zzyy;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 *      策略模式+工厂模式 解决 if else 嵌套过多问题
 *
 *      if (type == UserType.SILVER_VIP.getCode()) {
 *        System.out.println("白银会员 优惠50元");
 *        result = money - 50;
 *      } else if (type == UserType.GOLD_VIP.getCode()) {
 *        System.out.println("黄金会员 8折");
 *        result = money 0.8;
 *      } else if (type == UserType.PLATINUM_VIP.getCode()) {
 *        System.out.println("白金会员 优惠50元，再打7折");
 *        result = (money - 50) 0.7;
 *      } else {
 *        System.out.println("普通会员 不打折");
 *        result = money;
 *      }
 *      return result;
 */
@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);

        // 这里应该是从前端获取用户类型
        // int customerType = getCustomerTypeFromFrontend();
        // 根据客户类型判断是否打折
        int customerType = 2;
        long money = 1000;

        // 通过策略工厂获取策略并调用相应方法
        HandlerStrategy cocaStrategy = StrategyFactory.getStrategy(customerType);
        double compute = cocaStrategy.compute(money);
        System.out.println("计算结果：" + compute);
    }

    private static int getCustomerTypeFromFrontend() {
        return 1; // 假设获取到的是1
    }
}
